CSS Full Course Day 3 [Hindi] π» | CSS Box Model π | Mohit Decodes
π¦ CSS Tutorial β Day 3: CSS Box Model
Welcome to Day 3 of the CSS Full Course [Hindi] by Mohit Decodes! Todayβs lesson covers the CSS Box Model, a fundamental concept to understand how elements are sized and spaced on a webpage.
πΉ What is the CSS Box Model?
Every HTML element is a rectangular box composed of four parts:
- Content β The actual text or media inside the box
- Padding β Space between the content and the border
- Border β The edge around the padding
- Margin β Space outside the border, separating the element from others
πΉ Visual Representation:
lua
CopyEdit
+---------------------------+
| Margin |
| +---------------------+ |
| | Border | |
| | +---------------+ | |
| | | Padding | | |
| | | +-----------+ | | |
| | | | Content | | | |
| | | +-----------+ | | |
| | +---------------+ | |
| +---------------------+ |
+---------------------------+
βοΈ CSS Properties Related to Box Model:
width
&height
β size of content boxpadding
β inner spacingborder
β thickness and style of bordermargin
β outer spacing
π Example Code:
css
CopyEdit
div.box {
width: 200px;
padding: 20px;
border: 5px solid #333;
margin: 15px;
background-color: lightblue;
}
π‘ Important Tips:
- By default,
width
andheight
apply only to the content area. - Use
box-sizing: border-box;
to include padding and border within width/height. - Proper use of margin and padding controls spacing between elements.